package com.liuhaozzu.zookeeper.zookeeper_app.acl;

import java.io.IOException;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids;

public class DeleteNode {

	private static String path="/liuhaozzu-acl-delete";
	private static String path2="/liuhaozzu-acl-delete/child";
	
	public static void main(String[] args) throws Exception {
		ZooKeeper zk1=new ZooKeeper("hadoop1:2181",5000, null);
		zk1.addAuthInfo("digest", "foo:true".getBytes());
		
		zk1.create(path, "init".getBytes(), Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
		zk1.create(path2, "init".getBytes(), Ids.CREATOR_ALL_ACL, CreateMode.EPHEMERAL);
		
		try {
			ZooKeeper zk2=new ZooKeeper("hadoop1:2181", 5000, null);
			zk2.delete(path2, -1);
		} catch (Exception e) {
			System.out.println("删除子节点失败"+path2+e.getMessage());
		}
		ZooKeeper zk3=new ZooKeeper("hadoop1:2181", 5000, null);
		zk3.addAuthInfo("digest", "foo:true".getBytes());
		zk3.delete(path2, -1);
		System.out.println("删除节点成功"+path2);
		ZooKeeper zk4=new ZooKeeper("hadoop1:2181",50000,null);
		zk4.delete(path, -1);
		System.out.println("成功删除节点："+path);
	}
	
}
